<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>权限编辑</span>
      </div>

      <el-table
        :data="rightsList"
        style="width: 100%">
        <el-table-column
          header-align="center"
          align="center"
          type="index"
          label="#"
        >
        </el-table-column>
        <el-table-column
          prop="authName"
          label="权限名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="path"
          label="路径">
        </el-table-column>
        <el-table-column
          prop="level"
          label="等级"
          width="180">
          <template slot-scope="scope">
            <el-tag type="success" v-show="scope.row.level == 0" >一级</el-tag>
            <el-tag type="warning" v-show="scope.row.level == 1">二级</el-tag>
            <el-tag type="danger" v-show="scope.row.level == 2">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
<!--      <el-tree-->
<!--        ref="tree"-->
<!--        :data="rightsList"-->
<!--        :props=" { children: 'children', label: 'authName' }"-->
<!--        show-checkbox-->
<!--        node-key="id"-->
<!--        @node-click="handleNodeClick(rightsList)"></el-tree>-->
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rightsList: []
    }
  },
  methods: {
    getRightsList: async function() {
      const { data: list } = await this.$http.get('rights/list')
      if (list.meta.status !== 200) {
        return this.$message.error('获取权限失败')
      }
      this.rightsList = list.data
      console.log(list)
    },
    handleNodeClick(data) {
      console.log(data)
    }
  },
  created() {
    this.getRightsList()
  }
}
</script>

<style lang="less" scoped>
  .el-table {
    margin-top: 15px;
  }

  .block {
    margin-top: 15px;
  }
</style>
